﻿using System.Collections.Generic;
using System.Text;
using ZX.BLL.Extend;
using ZX.DBModule;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace ZX.Web.UI.Controls.UserControl
{
    public class MutiList : Literal
    {
        private string _tableName = "";
        [Description("数据来源的表名")]
        public string TableName
        {
            get { return _tableName; }
            set { _tableName = value; }
        }
        private string _caption = "";
        [Description("显示文本")]
        public string Caption
        {
            get { return this._caption; }
            set { _caption = value; }
        }
        private string _key = "";
        [Description("主键")]
        public string Key
        {
            get { return this._key; }
            set { _key = value; }
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (!DesignMode)
            {
                string sql = "Select "+Key+" as [Key],"+Caption+" as [Caption]  FROM "+TableName;
                IList<ListData> list = new EnttityBLL().GetEntitysBySqlComm<ListData>(sql);
                if (list == null)
                {
                    writer.Write("--No Data --");
                }
                StringBuilder _strHtml = new StringBuilder();
                _strHtml.Append("<Table  id='"+this.ID+"'><tr>");
                //_strHtml.Append("<td >ID</td>");
                _strHtml.Append("<td >名 称</td>");
                _strHtml.Append("</tr >");
                foreach (ListData listD in list)
                {
                    _strHtml.Append("<tr>");
                    //_strHtml.Append("<td>" + listD.Key + "</td>");
                    _strHtml.Append("<td>" + listD.Caption + "</td>");
                    _strHtml.Append("</tr >");
                }
                _strHtml.Append("</tr ></Table>");
                writer.Write(_strHtml.ToString());
                base.Render(writer);
            }
            else
            {
                writer.Write("列表菜单");
            }
        }
    }
}
